home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / tex / browse2.zip / BROWSE.ASM next >
Assembly Source File  |  1991-02-24  |  16KB  |  508 lines

  1. ;    BROWSE.ASM -- Full Screen File Pager
  2. ;    ====================================
  3.  
  4. CSEG        Segment
  5.         Assume    CS:CSEG, DS:CSEG, ES:CSEG, SS:CSEG
  6.         Org    0080h
  7. Parameter    Label    Byte
  8.         Org    0100h
  9. Entry:        Jmp Begin
  10.  
  11. ;    All Data
  12. ;    --------
  13.  
  14.         db    'ATTR='
  15. Attribute    db    0        ; Current screen attribute
  16.         db    'SHIFT='
  17. ShiftHoriz    db    8        ; Horizontal shift screen default
  18. DosVersionFail    db    'Requires DOS 2.0 or above$'
  19. NoSpaceFail    db    'Not enough memory$'
  20. FileFail    db    'File Not Found$'
  21. ScreenFail    db    'Unsupported video mode$'
  22. Delimiters    db    9,' ,;=/'    ; Delimiters in parameter
  23. FileHandle    dw    ?        ; Use for saving file handle
  24. WSMode        db    0FFh        ; AND value for non-WordStar mode
  25. LineLength    db    ?        ; Length of line (from BIOS)
  26. NumberLines    db    25,0        ; Number of lines (check EGA BIOS)
  27. ScreenSize    dw    ?        ; Size of screen in bytes
  28. CheckRetrace    db    1        ; Flag zero if EGA or MONO used
  29. Addr6845    dw    ?        ; Could use for retrace check    
  30. ScreenAddr    Label    DWord        ; Address of screen
  31. ScreenOff    dw    0        ; Higher for non-page 0
  32. ScreenSeg    dw    0B800h        ; Set to B000h for Mono Mode 7
  33. ScreenStart    dw    ?        ; Points within buffer 
  34. EndOfFile    dw    ?        ; Points within buffer
  35. FileOffset    dw    -1, -1        ; Address within file of buffer data
  36. HorizOffset    dw    0        ; Horizontal offset for display    
  37. RightMargin    dw    0        ; Right margin for offset display
  38. Dispatch    dw    Home, Up, PgUp, Dummy, Left
  39.         dw    Dummy, Right, Dummy, EndKEY, Down, PgDn
  40.  
  41. ;    Check DOS Version for 2.0 or above
  42. ;    ----------------------------------
  43.  
  44. Begin:        Cld            ; All string directions forward
  45.         Mov    AH,30h
  46.         Int    21h        ; Get DOS Version Number
  47.         Cmp    AL,2        ; Check for 2.0 or later
  48.         Jae    DOSVerOK
  49.         Mov    DX,Offset DOSVersionFail
  50. ErrorExit:    Mov    AH,9        ; Write error message
  51.         Int    21h
  52.         Int    20h
  53.  
  54. ;    Parse Command Line to get File Name and WordStar flag
  55. ;    -----------------------------------------------------
  56.  
  57. DOSVerOK:    Mov    SI,1 + Offset Parameter    ; Points to parameter
  58. NameSearch:    Lodsb                ; Get byte
  59.         Cmp    AL,13            ; Check if carriage return
  60.         Jz    NoFileFound        ; If so, no file name
  61.         Mov    DI,Offset Delimiters    ; String of delimiters
  62.         Mov    CX,5            ; Number of delimiters (no /)
  63.         Repne    Scasb            ; See if a match
  64.         Je    NameSearch        ; If a delimiter, keep looking
  65.         Mov    DX,SI            ; Otherwise found file name
  66.         Dec    DX            ; Points to beginning of it
  67. EndSearch:    Lodsb                ; Get next byte
  68.         Cmp    AL,13            ; See if carriage return
  69.         Je    GotFileEnd        ; If so, we're all done
  70.         Mov    DI,Offset Delimiters    ; String of delimiters
  71.         Mov    CX,6            ; Number (including /)
  72.         Repne    Scasb            ; See if a match
  73.         Jne    EndSearch        ; If not, still in file name
  74.         Mov    Byte Ptr [SI - 1],0    ; If so, mark end of file name
  75.         Jcxz    GotFlag            ; If slash, check for W
  76.         Jmp    EndSearch        ; Or continue flag search
  77. GotFlag:    Lodsb                ; Get byte after / flag
  78.         Or    AL,20h            ; Uncapitalize
  79.         Cmp    AL,'w'            ; See if w for WordStar mode
  80.         Jnz    GotFileEnd        ; If not, just ignore it
  81.         Mov    [WSMode],7Fh        ; AND value for WordStar
  82.  
  83. ;    Open the File
  84. ;    -------------
  85.  
  86. GotFileEnd:    Mov    Byte Ptr [SI - 1],0    ; Mark end of file name
  87.                         ; DX still points to name
  88.         Mov    AX,3D00h        ; Open file for reading
  89.         Int    21h            ;   by calling DOS
  90.         Jnc    GotTheFile        ; If no error, continue    
  91. NoFileFound:    Mov    DX,Offset FileFail    ; Otherwise print a message 
  92.         Jmp    ErrorExit
  93. GotTheFile:    Mov    [FileHandle],AX        ; Save the file handle
  94.  
  95. ;    Get Screen Mode Information from BIOS Data Area
  96. ;    -----------------------------------------------
  97.  
  98.         Push    ES            ; Save register
  99.         Sub    AX,AX
  100.         Mov    ES,AX            ; Set ES to 0 (BIOS Data)
  101.         Mov    AL,ES:[0449h]        ; Current Video Mode
  102.  
  103. ;;;
  104.         CMP    WORD PTR ES:[0463H],03D4H    ; MONOCHROME EMULATION?
  105.         JZ    CHK_IF_TEXT            ; NO
  106.         MOV    [SCREENSEG],0B000H        ; ELSE ADDRESS MONO
  107.         MOV    [CHECKRETRACE],0        ; NO RETR. CHECK NEEDED
  108. CHK_IF_TEXT:
  109. ;;;
  110.  
  111.         Cmp    AL,3            ; Check if Color Alpha
  112.         Jbe    DisplayOK        ; Continue if so
  113.         Cmp    AL,7            ; Check if monochrome display
  114.         Je    Monochrome        ; If so, branch
  115. ;;;
  116.         MOV    AX,1A00H        ; VGA-ONLY BIOS CALL: READ
  117.         INT    10H            ;  DISPLAY COMBINATION CODE
  118.         CMP    AL,1AH            ; VGA ADAPTER?
  119.         JNZ    TO_SCREENFAIL        ; NO, SORRY
  120.         MOV    [CHECKRETRACE],0    ; ELSE NO RETRACE CHECK NEEDED
  121.         MOV    DX,3CEH
  122.         MOV    AL,6            ; READ BIT 0 OF THE VGA GRAPHICS
  123.         CLI                ;  CONTROLLER'S "MISCELLANEOUS"
  124.         OUT    DX,AL            ;  REGISTER AT PORT 3CEh, INDEX
  125.         INC    DX            ;  6.  IF BIT IS SET THEN WE'RE
  126.         JMP    SHORT $+2        ;  *REALLY* IN A GRAPHICS MODE
  127.         IN    AL,DX            ;
  128.         STI                ;
  129.         TEST    AL,1            ; WELL?
  130.         JZ    DISPLAYOK        ; OKAY, NOT SET = NOT GRAPHICS
  131. TO_SCREENFAIL:
  132. ;;;
  133.  
  134.         Mov    DX,Offset ScreenFail    ; We can't handle graphics
  135.         Jmp    ErrorExit        ; So print an error message
  136. Monochrome:    Mov    [ScreenSeg],0B000h    ; Use Monochrome Segment
  137.         Mov    [CheckRetrace],0    ; Don't have to check retrace
  138. DisplayOK:    Mov    AL,ES:[044Ah]        ; Number of Columns
  139.         Mov    [LineLength],AL        ; Save it
  140.         Mov    AX,ES:[044Eh]        ; Offset into screen buffer
  141.         Mov    [ScreenOff],AX        ; Save it         
  142.         Mov    AX,ES:[0463h]        ; Address of 6845 Regsiter
  143.         Mov    [Addr6845],AX        ; Save it
  144.         Push    ES
  145.         Sub    DL,DL            ; Set Rows to zero first
  146.         Sub    BH,BH
  147.         Mov    AX,1130h        ; EGA BIOS: Get Information
  148.         Int    10h
  149.         Pop    ES
  150.         Or    DL,DL            ; Check if DL is still zero
  151.         Jz    NoEGA            ; If so, skip rest of stuff
  152.         Inc    DL
  153.         Mov    [NumberLines],DL    ; Save Number of Lines
  154.         Test    Byte Ptr ES:[0487h],4    ; Check if must check retrace
  155.         Jnz    NoEGA
  156.         Mov    [CheckRetrace],0    ; EGA says we don't have to
  157. NoEGA:        Mov    BH,ES:[0462h]        ; Get Current Page (use later)
  158.         Pop    ES
  159.         Mov    AL,[LineLength]        ; Length of each line
  160.         Mul    [NumberLines]        ; Total chars on screen
  161.         Add    AX,AX            ; Double for attributes
  162.         Mov    [ScreenSize],AX        ; And Save it
  163.  
  164. ;    See if enough memory is left
  165. ;    ----------------------------
  166.  
  167.         Add    AX,Offset ScreenHold    ; Add ScreenSize to code end
  168.         Add    AX,256            ; Add a little stack room
  169.         Cmp    AX,SP            ; Check against stack pointer
  170.         Jbe    GotEnufMemory        ; Continue if OK
  171.         Mov    DX,Offset NoSpaceFail    ; Otherwise end program
  172.         Jmp    ErrorExit        ;    with error messae
  173.         
  174. ;    Get Current Screen Attribute
  175. ;    ---------------------------- 
  176.  
  177. GotEnufMemory:    Cmp    [Attribute],0        ; Check if attribute pre-set
  178.         Jnz    GotAttribute        ; If so, move on
  179.         Mov    DL,' '            ; Write out a byte
  180.         Mov    AH,2            ;   using DOS
  181.         Int    21h
  182.         Mov    AL,8            ; Now backspace
  183.         Mov    AH,14            ;   using BIOS call
  184.         Int    10h
  185.         Mov    AH,8            ; Read character & attribute
  186.         Int    10h            ;   using BIOS call (BH = pg)
  187.         Mov    [Attribute],AH        ; And save attribute
  188.  
  189. ;    Save Current Screen
  190. ;    -------------------
  191.  
  192. GotAttribute:    Mov    DX,Offset Terminate    ; Set Ctrl-Break exit
  193.         Mov    AX,2523h        ;   to terminate that way
  194.         Int    21h
  195.  
  196. ;;;
  197.  
  198. SAVE_CURSOR:    MOV    AH,0FH
  199.         INT    10H              ; VIDEO PAGE INTO BH
  200.         MOV    AH,3
  201.         INT    10H              ; READ CURSOR POSITION
  202.         JMP    SHORT SAVE_CURSOR_2
  203. SAVED_CURSOR    DW    0              ; STORAGE SPACE (A KLUDGE, I KNOW)
  204. SAVE_CURSOR_2:    MOV    SAVED_CURSOR,DX
  205.         MOV    AH,2
  206.         MOV    DX,-1
  207.         INT    10H              ; CURSOR TO TIMBUKTU FOR NOW
  208.  
  209. ;;;
  210.  
  211.         Mov    DI,Offset ScreenHold    ; Destination of screen
  212.         Mov    CX,[ScreenSize]        ; Size of screen
  213.         Push    DS            ; Save Source Segment
  214.         Lds    SI,[ScreenAddr]        ; Get screen address
  215.         Rep    Movsb            ; Move in the bytes
  216.         Pop    DS            ; Restore Source Segment
  217.  
  218. ;    Get Keyboard Key and Decide on Action
  219. ;    -------------------------------------
  220.  
  221.         Call    Home            ; Read file in
  222.         Mov    [ScreenStart],SI    ; Set buffer address
  223. KeyLoop:    Call    UpDateScreen        ; Write file to screen
  224. GetKey:        Mov    AH,8            ; Get key
  225.         Int    21h            ;   by calling DOS
  226.         Cmp    AL,27            ; Check if ESC
  227.         Je    Terminate        ; If so, terminate 
  228.         Cmp    AL,0            ; Check if extended
  229.         Jnz    GetKey            ; If not, try again
  230.         Mov    AH,8            ; Get extended code
  231.         Int    21h            ;   by calling DOS
  232.         Sub    AL,71            ; Subtract Home key value
  233.         Jb    GetKey            ; If below that, not valid
  234.         Cmp    AL,(81 - 71)        ; Check if above PgDn
  235.         Ja    GetKey            ; If so, ignore it
  236.         Sub    AH,AH            ; Zero out top byte
  237.         Add    AX,AX            ; Double for word access
  238.         Mov    BX,AX            ; Offset in dispatch table
  239.         Mov    SI,[ScreenStart]    ; Set current buffer pointer
  240.         Call    [Dispatch + BX]        ; Do the call
  241.         Mov    [ScreenStart],SI    ; Set new buffer pointer
  242.         Jmp    KeyLoop            ; And update the screen
  243.  
  244. ;    Terminate -- Restore screen and close file
  245. ;    ------------------------------------------
  246.  
  247. Terminate:    Mov    SI,Offset ScreenHold    ; Address of